//
// Created by webturing on 2024/3/17.
//
#include<bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    for (int n; cin >> n;) {
        vector<pair<int, int>> a(n);
        for (auto &p: a) {
            cin >> p.first >> p.second;
        }
        sort(a.begin(), a.end(), [](const pair<int, int> &p, const pair<int, int> &q) {
            return p.second < q.second;
        });
        int start = 0, tot = 0;
        for (const auto &p: a) {
            if (p.first >= start) {
                ++tot;
                start = p.second;
            }
        }
        cout << tot << endl;
    }

    return 0;

}

